package com.sinoglobal.ningxia.activity.amusement;

import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.beans.BusinessDetailVo;
import com.sinoglobal.ningxia.frame.AbstractActivity;
import com.sinoglobal.ningxia.http.ConnectionUtil;
import com.sinoglobal.ningxia.utils.ItktLog;

import net.tsz.afinal.FinalBitmap;

import java.util.ArrayList;

/**
 * 
 * @author hxp
 * @createdate 2014-7-11 下午2:32:42
 * @Description: 照片墙，看大图
 */
public class PhotoBigActivity extends AbstractActivity {
	// private HackyViewPager hackyViewPager;// 照片大图viewpager
	private ExtendedViewPager extendedViewPager;
	private FinalBitmap fb;// 展示图片

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.photo_big);
		init();
	}

	// 初始化
	private void init() {
		fb = FinalBitmap.create(this);
		extendedViewPager = (ExtendedViewPager) findViewById(R.id.photo_big_viewpager);
		titleView.setText(getString(R.string.photo));
		BusinessDetailVo businessDetailVo = (BusinessDetailVo) getIntent().getSerializableExtra(BusinessDetailVo.class.getCanonicalName());
		ItktLog.i("businessDetailVo==" + businessDetailVo);
		if (null != businessDetailVo) {
			SimplePagerAdapter simplePagerAdapter = new SimplePagerAdapter(businessDetailVo.getImglist());
			extendedViewPager.setAdapter(simplePagerAdapter);
			extendedViewPager.setCurrentItem(businessDetailVo.getSelectedImgPosition());
		}
	}

	class SimplePagerAdapter extends PagerAdapter {
		ArrayList<String> imgList = new ArrayList<String>();

		public SimplePagerAdapter(ArrayList<String> imgList) {
			super();
			this.imgList = imgList;
			ItktLog.i("imgList==" + imgList);
		}

		@Override
		public int getCount() {
			return imgList == null ? 0 : imgList.size();
		}

		@Override
		public View instantiateItem(ViewGroup container, int position) {
			TouchImageView img = new TouchImageView(container.getContext());
			fb.display(img, ConnectionUtil.localUrl + imgList.get(position));
//			Uri uri=Uri.parse(ConnectionUtil.localUrl + imgList.get(position));
//			img.setImageURI(uri);
			container.addView(img, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
			return img;
		}

		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			container.removeView((View) object);
		}

		@Override
		public boolean isViewFromObject(View view, Object object) {
			return view == object;
		}

	}
}
